package jman.competition15;

import java.sql.ResultSet;
import java.sql.SQLException;

public class UserDao {
	public User getUserByUserName(String userName) throws SQLException{
		User user=new User();
		Dao d=new Dao();
		d.start();
		String sql="select * from user where username='"+userName+"'";
		ResultSet rs=d.read(sql);
		while(rs.next()){
			user=new User(userName,rs.getString(2),rs.getString(3));
		}
		d.close();
		return user;
	}
	public boolean addUser(User user){
		boolean flag=false;
		String sql="insert into user (username,password,sex) values ('"+user.getUserName()+"','"+user.getPassword()+"','"+user.getSex()+"')";
		Dao d=new Dao();
		d.start();
		flag=d.add(sql);
		d.close();
		return flag;
	}
}
